package io;

import java.io.*;
import java.net.Socket;
import java.net.*;

/**
 * Created by fanzhenyu02 on 2020/7/4.
 */
public class SocketClient {

    public static int port = 4343; //端口号

    public static void requestServer() {
        // Socket 客户端（接收信息并打印）
        try (Socket clientSocket = new Socket(InetAddress.getLocalHost(), port)) {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
            bufferedReader.lines().forEach(s -> System.out.println("接收到服务端响应：" + s));
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public static void main(String[] args) throws Exception {
        for (int i = 0; i < 100; i++) {
            requestServer();
            Thread.sleep(100);
        }
    }

}
